@tool
class_name Guard_StateChartExpressionPropertyTrigger
extends Guard

@export var key:String
## 是否必须在同一帧才处理
@export var is_must_same_frame:bool = true
## 是否在帧尾清空这个key
@export var is_clear_when_end_of_frame:bool = true

func is_satisfied(transition:Transition,state:State) -> bool:
	var cur_value = state.chart.get_expression_property(key,null)
	if is_clear_when_end_of_frame:
		var f = func():state.chart.set_expression_property(key,null)
		f.call_deferred()
	return cur_value == Engine.get_process_frames() if is_must_same_frame else cur_value != null

func _init() -> void:
	if Engine.is_editor_hint():
		resource_local_to_scene = true
